//
//  UIButton+Theme.m
//  夜间模式
//
//  Created by Burn on 2018/10/21.
//  Copyright © 2018年 buren. All rights reserved.
//

#import "UIButton+Theme.h"
#import <objc/runtime.h>
#import "ThemeManager.h"

@implementation UIButton (Theme)

- (void)setType:(id)type{
    objc_setAssociatedObject(self, @selector(type), type, OBJC_ASSOCIATION_ASSIGN);
}

- (id)type{
    return objc_getAssociatedObject(self, @selector(type));
}

- (void)changeColor{
//    [super changeColor];
    switch ([self.type integerValue]) {
        case ThemeTypeNormal:
            [self setTitleColor:[ThemeManager shareInstance].themeNormalColor forState:UIControlStateNormal];
            break;
        case ThemeTypeBlack:
            [self setTitleColor:[ThemeManager shareInstance].themeBlackColor forState:UIControlStateNormal];
            break;
        case ThemeTypeRed:
            [self setTitleColor:[ThemeManager shareInstance].themeRedColor forState:UIControlStateNormal];
            break;
        case ThemeTypeClear:
            [self setTitleColor:[ThemeManager shareInstance].themeClearColor forState:UIControlStateNormal];
            break;
            
        default:
            break;
    }
}

- (void)nightTextType:(ThemeType)type{
    self.type = [NSNumber numberWithInteger:type];
    [self changeColor];
    [self startMonitoer];
}

- (void)startMonitoer{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeColor) name:@"CHANGECOLOR" object:nil];
}

@end
